/**
 * Copyright (c) MaibornWolff et al GmbH 2011
 * 
 * This software is copyrighted. It may only be used for the purposes
 * stipulated in the license agreement, subject to copyright regulations, in
 * particular to �� 69 a ff. of the German Copyright Act. 
 * Any usage not within the scope of Copyright Act without MaibornWolff et al GmbH consent
 * is inadmissible and liable to prosecution.
 * 
 * MaibornWolff et al GmbH has installed the copyright notice stipulated 
 * herein in the computer program. In the event of an user being authorized to
 * duplicate the computer program, this copyright notice always is to be 
 * included. The copyright notice must neither be changed nor destroyed.
 * 
 * Contact Information: 
 * MaibornWolff et al GmbH, Theresienhoehe 13, 80339 Munich, info@mwea.de
 **/
package de.hm.edu.kinderfinder.contentprovider;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Diese Klasse erstellt und bearbeitet das Datenbankschema
 * 
 * @author Lukas Jarosch, Christoph-Samuel Pitter
 * 
 */
public class DataBase extends SQLiteOpenHelper {

	private static final String DB_NAME = "cache.db";
	private static final int DB_VERSION = 1;
	public static final String ZONENAME = "ZONENAME";
	public static final String LATITUDE = "LATITUDE";
	public static final String LONGITUDE = "LONGITUDE";
	public static final String RADIUS = "RADIUS";
	public static final String TIMESTART = "TIMESTART";
	public static final String TIMEEND = "TIMEEND";
	public static final String ID = "_id";
	public static final String TABLE_NAME = "ZONES";
	public static final String MONDAY = "MONDAY";
	public static final String TUESDAY = "TUESDAY";
	public static final String WEDNESDAY = "WEDNESDAY";
	public static final String THURSDAY = "THURSDAY";
	public static final String FRIDAY = "FRIDAY";
	public static final String SATURDAY = "SATURDAY";
	public static final String SUNDAY = "SUNDAY";
	private static final String CACHE_CREATE = "CREATE TABLE " + TABLE_NAME
			+ " (" + ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + ZONENAME
			+ " TEXT NOT NULL, " + LATITUDE + " REAL NOT NULL, " + LONGITUDE
			+ " REAL NOT NULL, " + RADIUS + " INTEGER NOT NULL," + TIMESTART
			+ " BIGINT NOT NULL," + TIMEEND + " BIGINT NOT NULL," + MONDAY
			+ " INTEGER NOT NULL," + TUESDAY + " INTEGER NOT NULL," + WEDNESDAY
			+ " INTEGER NOT NULL," + THURSDAY + " INTEGER NOT NULL," + FRIDAY
			+ " INTEGER NOT NULL," + SATURDAY + " INTEGER NOT NULL," + SUNDAY
			+ " INTEGER NOT NULL" + ")";
	private static final String CACHE_DROP = "DROP TABLE IF EXISTS "
			+ TABLE_NAME;

	/**
	 * Standartkonstruktor für die Database
	 * 
	 * @param context
	 *            der aktuellen Aktivity
	 */
	public DataBase(Context context) {
		super(context, DB_NAME, null, DB_VERSION);
	}

	/**
	 * initialisiert die Datenbank
	 * 
	 * @param die
	 *            Datenbank
	 */
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(CACHE_CREATE);
	}

	/**
	 * wir aufgerufen wenn ein upgrade der Datenbank durchgeführt werden soll.
	 * In diesem fall ist es ein reset.
	 * 
	 * @param db
	 *            zurückzusetztende Datenbank
	 * @param oldVersion
	 *            wird nicht verwendet
	 * @param newVersion
	 *            wird nicht verwendet
	 */
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL(CACHE_DROP);
		onCreate(db);
	}

}
